/*
 * This file is Copyright 2002-2006 Loyola University Chicago,
 * Department of Computer Science and the Emerging Technologies Laboratory.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License via
 *    http://www.apache.org/licenses/LICENSE-2.0.
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.citep.formats.ofx;
import java.util.Date;
import java.math.BigDecimal;


public class OFXTransaction {

	//mandatory elements
	private String accountId; //matches with the relevant account id in your application
	private OFXAccount account;
	private TransactionType transactionType;
	private InvTransactionType invTransactionType;
	private BigDecimal units; //Variation of the number of units of the commodity Suppose units is -10, ave unitprice is 1. If the commodity is stock, you have 10 less stock, but 10 more dollars in you amccount (fees not considered, see amount). If commodity is money, you have 10 less dollars in your pocket, but 10 more in your account
	private BigDecimal unitPrice; //Value of each unit, 1.00 if the commodity is money
	private BigDecimal amount; //Total monetary amount of the transaction, signage will determine if money went in or out. amount is the total amount: -(units) * unitprice - various fees
	private String fi_id; //Generated by the financial institution (fi), unique id of the transaction, to be used to detect duplicate downloads
	
	
	//optional elements
	private String uniqueId; //The id of the security being traded. Mandatory for investment transactions
	private String uniqueIdType; //Usially "CUSIP" for FIs in north america
	private OFXSecurity security; 
	private Date datePosted; //Date the transaction took effect (ex: date it appeared on your credit card bill). Setlement date; for stock split, execution date.
	private Date dateInitiated; //Date the transaction was initiated (ex: date you bought something in a store for credit card; trade date for stocks; day of record for stock split)
	private Date dateFundsAvailable; //Date the funds are available (not always provided) (ex: the date you are allowed to withdraw a deposit
	private String fi_id_corrected; //if fi_id_corrected is present, this transaction is meant to replace or delete the transaction with this fi_id.
	private String serverTransactionId; //Used for user initiated transaction such as payment or funds transfer. Can be seen as a confirmation number.
	private String checkNumber; //The check number is most likely an integer and can probably be converted properly with atoi(). However the spec allows for up to 12 digits, so it is not garanteed to work
	private String referenceNumber; //Might present in addition to or instead of a check_number. Not necessarily a number
	private long standardIndustrialCode; //The standard industrial code can have at most 6 digits
	private String playeeId; //The identifier of the payee
	private String name; //Can be the name of the payee or the description of the transaction
	private String memo; //Extra information not included in name
	private double commission; //Commission paid to broker (investment transactions only)
	private double fees; //Fees applied to trade (investment transactions only)
	private double oldunits;
	private double newunits;

	public OFXAccount getAccount() {
		return account;
	}
	
	public void setAccount(OFXAccount account) {
		this.account = account;
	}
	
	public String getAccountId() {
		return accountId;
	}
	
	public void setAccountId(String accountId) {
		this.accountId = accountId;
	}
	
	public BigDecimal getAmount() {
		return amount;
	}
	
	public void setAmount(BigDecimal amount) {
		this.amount = amount;
	}
	
	public String getCheckNumber() {
		return checkNumber;
	}
	
	public void setCheckNumber(String checkNumber) {
		this.checkNumber = checkNumber;
	}
	
	public double getCommission() {
		return commission;
	}
	
	public void setCommission(double commission) {
		this.commission = commission;
	}
	
	public Date getDateFundsAvailable() {
		return dateFundsAvailable;
	}
	
	public void setDateFundsAvailable(Date dateFundsAvailable) {
		this.dateFundsAvailable = dateFundsAvailable;
	}
	
	public Date getDateInitiated() {
		return dateInitiated;
	}
	
	public void setDateInitiated(Date dateInitiated) {
		this.dateInitiated = dateInitiated;
	}
	
	public Date getDatePosted() {
		return datePosted;
	}
	
	public void setDatePosted(Date datePosted) {
		this.datePosted = datePosted;
	}
	
	public double getFees() {
		return fees;
	}
	
	public void setFees(double fees) {
		this.fees = fees;
	}
	
	public String getFi_id() {
		return fi_id;
	}
	
	public void setFi_id(String fi_id) {
		this.fi_id = fi_id;
	}
	
	public String getFi_id_corrected() {
		return fi_id_corrected;
	}
	
	public void setFi_id_corrected(String fi_id_corrected) {
		this.fi_id_corrected = fi_id_corrected;
	}
	
	public InvTransactionType getInvTransactionType() {
		return invTransactionType;
	}
	
	public void setInvTransactionType(InvTransactionType invTransactionType) {
		this.invTransactionType = invTransactionType;
	}
	
	public String getMemo() {
		return memo;
	}
	
	public void setMemo(String memo) {
		this.memo = memo;
	}

	public String getName() {		
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public double getNewunits() {
		return newunits;
	}
	
	public void setNewunits(double newunits) {
		this.newunits = newunits;
	}
	
	public double getOldunits() {
		return oldunits;
	}
	
	public void setOldunits(double oldunits) {
		this.oldunits = oldunits;
	}
	
	public String getPlayeeId() {
		return playeeId;
	}
	
	public void setPlayeeId(String playeeId) {
		this.playeeId = playeeId;
	}
	
	public String getReferenceNumber() {
		return referenceNumber;
	}
	
	public void setReferenceNumber(String referenceNumber) {
		this.referenceNumber = referenceNumber;
	}
	
	public OFXSecurity getSecurity() {
		return security;
	}
	
	public void setSecurity(OFXSecurity security) {
		this.security = security;
	}
	
	public String getServerTransactionId() {
		return serverTransactionId;
	}
	
	public void setServerTransactionId(String serverTransactionId) {
		this.serverTransactionId = serverTransactionId;
	}

	public long getStandardIndustrialCode() {
		return standardIndustrialCode;
	}
	
	public void setStandardIndustrialCode(long standardIndustrialCode) {
		this.standardIndustrialCode = standardIndustrialCode;
	}
	
	public TransactionType getTransactionType() {
		return transactionType;
	}
	
	public void setTransactionType(TransactionType transactionType) {
		this.transactionType = transactionType;
	}
	
	public String getUniqueId() {
		return uniqueId;
	}
	
	public void setUniqueId(String uniqueId) {
		this.uniqueId = uniqueId;
	}
	
	public String getUniqueIdType() {
		return uniqueIdType;
	}
	
	public void setUniqueIdType(String uniqueIdType) {
		this.uniqueIdType = uniqueIdType;
	}
	
	public BigDecimal getUnitPrice() {
		return unitPrice;
	}
	
	public void setUnitPrice(BigDecimal unitPrice) {
		this.unitPrice = unitPrice;
	}
	
	public BigDecimal getUnits() {
		return units;
	}
	
	public void setUnits(BigDecimal units) {
		this.units = units;
	}

	public String toString() {

		return String.format("Transaction: accountId=%s, account=%s, name=%s, memo=%s, transactionType=%s, invTransactionType=%s, units=%s, unitPrice=%s, amount=%s, fi_id=%s, datePosted=%s", 
				accountId,account,name,memo,transactionType,invTransactionType, units,unitPrice,amount,fi_id, datePosted);
	}
	

}

